package cn.iocoder.yudao.module.book.dal.mysql.posts;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.book.dal.dataobject.posts.PostsDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.book.controller.admin.posts.vo.*;

/**
 * 社区动态 Mapper
 *
 * @author ding
 */
@Mapper
public interface PostsMapper extends BaseMapperX<PostsDO> {

    default PageResult<PostsDO> selectPage(PostsPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<PostsDO>()
                .eqIfPresent(PostsDO::getUserId, reqVO.getUserId())
                .eqIfPresent(PostsDO::getCategory, reqVO.getCategory())
                .eqIfPresent(PostsDO::getTitle, reqVO.getTitle())
                .eqIfPresent(PostsDO::getContent, reqVO.getContent())
                .eqIfPresent(PostsDO::getStudyDuration, reqVO.getStudyDuration())
                .eqIfPresent(PostsDO::getStudyPages, reqVO.getStudyPages())
                .eqIfPresent(PostsDO::getStudyContent, reqVO.getStudyContent())
                .eqIfPresent(PostsDO::getRelatedBookId, reqVO.getRelatedBookId())
                .eqIfPresent(PostsDO::getRelatedCollectionId, reqVO.getRelatedCollectionId())
                .eqIfPresent(PostsDO::getRelatedClockId, reqVO.getRelatedClockId())
                .eqIfPresent(PostsDO::getLikesCount, reqVO.getLikesCount())
                .eqIfPresent(PostsDO::getCommentsCount, reqVO.getCommentsCount())
                .eqIfPresent(PostsDO::getSharesCount, reqVO.getSharesCount())
                .eqIfPresent(PostsDO::getStatus, reqVO.getStatus())
                .eqIfPresent(PostsDO::getIsTop, reqVO.getIsTop())
                .betweenIfPresent(PostsDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(PostsDO::getPostId));
    }

}